<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/**
* 
*/
class Report extends MY_Controller
{
	
	public function __construct()
	{
		parent::__construct();
		
		$this->load->model('User/ReportModel','report');
	}

	//列表页
	public function index()
	{
		$this->load->view('report_list');
	}


	//获取数据
	public function get_list()
	{
		$page = $this->input->get('page');
		$page = $page ? $page : 1;

		$term['keyword'] = $this->input->get('keyword');

		$res = $this->report->get_list_data($term,$page);
		
		$this->load->model('User/UserCardModel','user_card');
		foreach($res['list'] as $k=>$v){
			$card = $this->user_card->get_info($v['card_id']);			
			$res['list'][$k]['card_name'] = '';
			if($card){				
				$res['list'][$k]['card_name'] = isset($card['card_name'])?$card['card_name']:'';
			}
		}
		
		if ($res) 
		{
			$data = $res;
			$data['status'] = 200;
			$data['message'] = '获取成功！';
		}
		else
		{
			$data['status'] = 400;
			$data['message'] = '数据获取失败！';
		}

		echo json_encode($data);exit();
	}


	//添加签到
	public function add_appoint()
	{
		$this->load->view('report_info');
	}


	//获取会员信息
	public function get_user_list()
	{
		$user = $this->input->get('user', TRUE);

		$res = $this->report->get_user($user);

		$data['list'] = $res;

		echo json_encode($data);exit();
	}


	//获取会员预约信息
	public function appoint_list()
	{
		$user_id = $this->input->get('user_id', TRUE);

		$res = $this->report->appoint_data($user_id);

		if ($res)
		{
			$data['list'] = $res;
			$data['status'] = 200;
			$data['message'] = '取消成功！';
		}
		else{
			$data['status'] = 400;
			$data['message'] = '取消失败！';
		}

		echo json_encode($data);exit();
	}


	//添加签到
	public function insert_user_appoint()
	{
		$appoint_id = $this->input->get('aid', true);
		$arr['status'] = 1;

		$res = $this->report->update_appoint($arr,$appoint_id);

		if ($res){
			$data['status'] = 200;
			$data['message'] = '签到成功！';
		}
		else{
			$data['status'] = 400;
			$data['message'] = '签到失败！';
		}

		echo json_encode($data);exit();
	}



	//取消签到
	public function cancel_appoint()
	{
		$appoint_id = $this->input->get('id', true);
		$arr['status'] = 0;

		$res = $this->report->cancel_user_appoint($arr,$appoint_id);

		if ($res){
			$data['status'] = 200;
			$data['message'] = '取消成功！';
		}
		else{
			$data['status'] = 400;
			$data['message'] = '取消失败！';
		}

		echo json_encode($data);exit();
	}


}






?>